<?php
/**
 * Handles the inserting of files through the HTTP post protocol
 * The structure of the incoming post array should look like this:
 * 
 * $_POST['username'] => "username"
 * $_POST['password'] => "password"
 * $_POST['file1_data'] => Base64 encoded string with the filedata
 * $_POST['file1_name'] => Name of the file
 * $_POST['file2_data'] => Base64 encoded string with the filedata
 * $_POST['file2_name'] => Name of the file
 * 
 * and so on
 * 
 * @author Gustav Knutsson
 */
class jdInsert_Post{
	// Holds the jdDatabase object for this class.
	//private $jddb;
	
	// jdDatabase mysql object
	private $jddb;
	
	// The username, stored in this class for validation
	private $username;
	
	// The password, stored in this class for validation
	private $password;
	
	// The userID if any.
	public $u_id;
	
	/**
	 * Class construct, it checks the username and password validity in the jdDatabase.
	 * 
	 * @param STRING $username
	 * @param STRING $password
	 * @return bool
	 * 
	 * @author Gustav Knutsson
	 * @access public
	 */
	public function __construct($username, $password){
		$this->jddb = jdDatabaseMySql::getInstance();
		$this->username = $username;
		$this->password = $password;
	}
	
	/**
	 * Validates the user against the user database.
	 * 
	 * @return bool
	 * 
	 * @author Gustav Knutsson
	 * @access public
	 */
	public function isValidUser(){
		$rad = $this->jddb->fetch("
		SELECT u_id 
		FROM users 
		WHERE u_username = '".$this->username."'
		AND u_password = '".$this->password."'
		AND u_mode = 'enabled'
		LIMIT 1");
		
		if(count($rad) > 0){
			$this->u_id = $rad[0]['u_id'];
			return true;
		}else{
			return false;
		}
	}
}
?>